package cw.spring.security.acl.poc.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name = "Acl_Object_Identity")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AclObjectIdentityModel {

  private AclClassModel objectIdClass;
  private Integer objectIdIdentity;
  private AclObjectIdentityModel parentEntity;

  @ManyToOne
  @JoinColumn(name = "parent_object", nullable = true)
  public AclObjectIdentityModel getParentEntity() {
    return parentEntity;
  }

  public void setParentEntity(AclObjectIdentityModel parentEntity) {
    this.parentEntity = parentEntity;
  }

  private AclSidModel ownerSid;
  private Boolean entriesInheriting;

  private long id;

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  public long getId() {
    return id;
  }

  public void setId(long id) {
    this.id = id;
  }

  @ManyToOne
  @Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN })
  @JoinColumn(name = "object_id_class", nullable = false)
  public AclClassModel getObjectIdClass() {
    return objectIdClass;
  }

  public void setObjectIdClass(AclClassModel objectIdClass) {
    this.objectIdClass = objectIdClass;
  }

  @Column(name = "object_id_identity")
  public Integer getObjectIdIdentity() {
    return objectIdIdentity;
  }

  public void setObjectIdIdentity(Integer objectIdIdentity) {
    this.objectIdIdentity = objectIdIdentity;
  }

  @ManyToOne
  @Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN })
  @JoinColumn(name = "own_sid", nullable = false)
  public AclSidModel getOwnerSid() {
    return ownerSid;
  }

  public void setOwnerSid(AclSidModel ownerSid) {
    this.ownerSid = ownerSid;
  }

  @Column(name = "entries_inheriting")
  public Boolean getEntriesInheriting() {
    return entriesInheriting;
  }

  public void setEntriesInheriting(Boolean entriesInheriting) {
    this.entriesInheriting = entriesInheriting;
  }

}
